//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#include "Graphics/Resources/Program.h"

namespace Engine
{
namespace Graphics
{
	
/*
=================================================
	constructor
=================================================
*/
	Program::Program (const EngineSubSystemsRef ess) :
		Resource(EResource::PROGRAM, ess), _numTextures(0)
	{}
		
/*
=================================================
	destructor
=================================================
*/
	Program::~Program ()
	{}
	
/*
=================================================
	AddTexture
=================================================
*/
	Program & Program::AddTexture (uni_c_string uniformName, const Sampler &samp)
	{
		if ( _numTextures >= _textures.Count() )
		{
			WARNING("");
			return *this;
		}

		_textures[_numTextures].uniform.GetLocation( _program, uniformName );
		_textures[_numTextures].sampler = samp;
		_textures[_numTextures].enabled = true;

		++_numTextures;
		return *this;
	}
		
/*
=================================================
	SwapData
=================================================
*/
	bool Program::SwapData (const ResourcePtr &res)
	{
		CHECK_ERR( Resource::SwapData( res ) );

		Program *	prog = (Program *) res.ptr();

		_swap( this->_textures,		prog->_textures );
		_swap( this->_renderState,	prog->_renderState );
		_swap( this->_numTextures,	prog->_numTextures );
		_swap( this->_attribs,		prog->_attribs );
		_swap( this->_program._id,	prog->_program._id );

		return true;
	}
		
/*
=================================================
	IsLoadedWithParams
=================================================
*/
	bool Program::IsLoadedWithParams (const ResLoadParams &params) const
	{
		return Resource::IsLoadedWithParams( params );
	}
	
/*
=================================================
	IsValid
=================================================
*/
	bool Program::IsValid () const
	{
		return _program.Id() != 0;
	}
	
/*
=================================================
	New
=================================================
*/
	ProgramPtr Program::New (const EngineSubSystemsRef ess)
	{
		return BaseObject::_New( new Program( ess ) );
	}
	
/*
=================================================
	GetDefaultLoadParams
=================================================
*/
	Program::ProgramLoadParams Program::GetDefaultLoadParams ()
	{
		ProgramLoadParams	params;
		return params;
	}
	
}	// Graphics
}	// Engine